<template>
  <!-- @click="close" -->
  <div class="mobile-actionsheet" v-show="visible">
    <transition name="bounce" enter-active-class="bounceInUp" leave-active-class="bounceOutDown">
      <ul class="actionsheet" v-if="visible">
        <li
          class="actionsheet-item"
          v-for="button in buttons"
          :key="button.value"
          @click="onClickButton(button)">{{ button.name }}</li>
        <li class="actionsheet-item cancel" @click="close">cancel</li>
      </ul>
    </transition>
  </div>
</template>
<script>
export default {
  name: 'MobileActionSheet',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    record: {
      type: Object,
      default: () => ({})
    },
    buttons: {
      type: Array,
      default: () => ([]) // [{ name, value }]
    }
  },
  methods: {
    onClickButton(button) {
      this.$emit('confirm', button.value)
      this.close()
    },
    close() {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss">
.mobile-actionsheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 2;
  .actionsheet {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    margin: 0;
    padding: 0 .3rem .2rem;
    &-item {
      display: flex;
      align-items: center;
      justify-content: center;
      height: .8rem;
      background-color: #fff;
      border-radius: .2rem;
      margin-bottom: .1rem;
      color: #0079FF;
      font-size: .3rem;
      &.cancel {
        color: #FF3930;
        margin-top: .3rem;
      }
    }
  }
}
</style>
